<?php

class IndexController extends Zend_Controller_Action 
{
    public function indexAction(){

	}

	public function addmarkerAction(){		
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->setLayout('layout-ajax');
		
		$dbAdapter = Zend_Registry::getInstance()->dbAdapter;
			
		if ($this->getRequest()->isGet()) {
			$markers = new Marker();
			$row = $markers->createRow();
			$row->lat = $this->getRequest()->getParam('lat');
			$row->lng = $this->getRequest()->getParam('lng');
			$row->information = $this->getRequest()->getParam('information');
			$row->date = date('Y-m-d');
			$row->save();			
		}		
	}
	
	public function savedmarkersAction(){
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->setLayout('layout-ajax');
		
		$markers = new Marker();
		
		$xmlDoc = new DOMDocument('1.0','utf-8');
		
		$xmlDoc->formatOutput = true;
		
		$parent = $xmlDoc->createElement('markers');
		
		$parent = $xmlDoc->appendChild($parent);
		
		foreach ($markers->fetchAll($markers->select()->order('date ASC')) as $marker){
			$child = $xmlDoc->createElement('marker');
			$child->setAttribute('lat',$marker['lat']);
			$child->setAttribute('lng',$marker['lng']);
			$child->setAttribute('information',$marker['information']);
			$child->setAttribute('date',$marker['date']);		
			$child = $parent->appendChild($child);
		}
		
		echo $xmlDoc->saveXML();
	}
}
